home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / SELFTREE.ZIP / selftree / include / selftree.inc < prev   
Encoding:
Text File  |  1997-09-02  |  16.6 KB  |  376 lines

  1. /*********************************************************************
  2. *                                                                    *
  3. * This is the selftree-include-file for POVRay.                      *
  4. * c1997 by Stephan Kuhagen                                           *
  5. *                                                                    *
  6. * Description: the include-file generates another include-file which *
  7. *  generates a recursive tree-object. Has thousands of parameters    *
  8. *  (which is not a feature, but not a bug also... I think...) and    *
  9. *  is very diffcult to use (but better than constructing your trees  *
  10. *  by hand) and takes a millennium to render... You be warned.       *
  11. *                                                                    *
  12. * Usage: define many many variables, then include selftree.inc and   *
  13. *  then include the tree-include which you have made with            *
  14. *  -GDFILENAME and say object { OBJECTNAME }.                        *
  15. *  The include has reasonable defaults, but you can find much better *
  16. *  values for more realistic trees. Look at the documentation and    *
  17. *  the example-files included in the distribution.                   *
  18. *                                                                    *
  19. * Copyright: You may use it, as you like. If you want to distribute  *
  20. *  the include, ask me for permission, I will give you...            *
  21. *                                                                    *
  22. *********************************************************************/
  23.  
  24.  
  25.  
  26. /*********************************************************************
  27. *                                                                    *
  28. * Set default-values for the variables                               *
  29. *                                                                    *
  30. *********************************************************************/
  31.  
  32.  
  33. #ifndef ( OBJECTNAME)
  34.    #declare OBJECTNAME       = "TREE"      // Name of the tree-object (STRING)
  35. #end
  36.  
  37. #ifndef ( USESTDTRUNK)
  38.    #declare USESTDTRUNK      = "YES"       // Should we use the predefined trunk? (BOOL: YES/NO)
  39. #end
  40.  
  41. #ifndef ( TRUNKLEN)
  42.    #declare TRUNKLEN         = "5"         // How long should the trunk be? (FLOAT, >0)
  43. #end
  44.  
  45. #ifndef ( TRUNKBASER)
  46.    #declare TRUNKBASER       = "0.7"       // The trunk-radius at the floor. (FLOAT, >0)
  47. #end
  48.  
  49. #ifndef ( TRUNKCAPR)
  50.    #declare TRUNKCAPR        = "0.5"       // The trunk-radius at the top. (FLOAT, >0)
  51. #end
  52.  
  53. #ifndef ( DEPTH)
  54.    #declare DEPTH            = 6           // The recursion-depth (use with care!) (INT, >0)
  55. #end
  56.  
  57. #ifndef ( BLEN)
  58.    #declare BLEN             = "5"         // The length of a branch in the first recursion-step (minimum) (FLOAT, >0)
  59. #end
  60.  
  61. #ifndef ( LDIFF)
  62.    #declare LDIFF            = "0"         // A difference for the branch-legth (would be added to BLEN) (FLOAT, LDIFF> -BLEN)
  63. #end
  64.  
  65. #ifndef ( RADIUS)
  66.    #declare RADIUS           = "0.5"       // The start radius for the branches (FLOAT, >0)
  67. #end
  68.  
  69. #ifndef ( RADSCALE)
  70.    #declare RADSCALE         = "0.5"       // The scale for the branch-radius (FLOAT, >0) 
  71. #end
  72.  
  73. #ifndef ( RDIFF)
  74.    #declare RDIFF            = "0"         // A difference for the branch-radius (would be subtracted from RADIUS) (FLOAT, |RDIFF|<RADIUS)
  75. #end
  76.  
  77. #ifndef ( RECSCALE)
  78.    #declare RECSCALE         = "0.5"       // The scale for the recursion (FLOAT, >0)
  79. #end
  80.  
  81. #ifndef ( SLOPEANGLE)
  82.    #declare SLOPEANGLE       = "40"        // The slope-angle for the branches (FLOAT)
  83. #end
  84.  
  85. #ifndef ( SANGLEDIFF)
  86.    #declare SANGLEDIFF       = "0"         // A difference for the slope-angle (would be added to SLOPEANGLE) (FLOAT)
  87. #end
  88.  
  89. #ifndef ( ANGLESCALE)
  90.    #declare ANGLESCALE       = "1.1"       // The scale for the for the slope-angle (FLOAT)
  91. #end
  92.  
  93. #ifndef ( NRBRANCHES)
  94.    #declare NRBRANCHES       = "4"         // The number of branches (INT, >0)
  95. #end
  96.  
  97. #ifndef ( NRBDIFF)
  98.    #declare NRBDIFF          = "0"         // A difference for the number of branches (would be added to NRBRANCHES) (FLOAT)
  99. #end
  100.  
  101. #ifndef ( NRBSCALEADD)
  102.    #declare NRBSCALEADD      = "0"         // A scale for the number of branches (would be added to NRBRANCHES addiert)(FLOAT)
  103. #end
  104.  
  105. #ifndef ( NRBSCALEMUL)
  106.    #declare NRBSCALEMUL      = "1"         // Another scale for the number of branches  (would be multiplied with NRBRANCHES)(FLOAT)
  107. #end
  108.  
  109. #ifndef ( BRANCHTOP)
  110.    #declare BRANCHTOP        = "0.6"       // The chance for a branch to sit at the top of its parent or randomly at another place. (FLOAT, 0<=x<=1)
  111. #end
  112.  
  113. #ifndef ( LEAFINC)
  114.    #declare LEAFINC          = "NO"        // Are there leafs? (STRING, YES|NO)
  115. #end
  116.  
  117. #ifndef ( NRLEAFINCS)
  118.    #declare NRLEAFINCS       = 0           // How many leafs are there? (INT, >=0)
  119. #end
  120.  
  121. #ifndef ( NRLEAFS)
  122.    #declare NRLEAFS          = "0"         // Number of leafs per branch (INT, >=0)
  123. #end
  124.  
  125. #ifndef ( NRLDIFF)
  126.    #declare NRLDIFF          = "0"         // A difference for the number of leafs (would be added to NRLEAFS)(INT, NRLDIFF> -NRLEAFS)
  127. #end
  128.  
  129. #ifndef ( ROTRANGE)
  130.    #declare ROTRANGE         = "360"       // The range for the rotation-angle of the branches (FLOAT, 0<=x<=360)
  131. #end
  132.  
  133. #ifndef ( RANDINIT_ROT)
  134.    #declare RANDINIT_ROT     = "1.1234"    // The startvalue for the random-generator for rotations (FLOAT)
  135. #end
  136.  
  137. #ifndef ( RANDINIT_LDIFF)
  138.    #declare RANDINIT_LDIFF   = "0.1234"    // The startvalue for the random-generator for LDIFF (FLOAT)
  139. #end
  140.  
  141. #ifndef ( RANDINIT_RDIFF)
  142.    #declare RANDINIT_RDIFF   = "0.1234"    // The startvalue for the random-generator for RDIFF (FLOAT)
  143. #end
  144.  
  145. #ifndef ( RANDINIT_SDIFF)
  146.    #declare RANDINIT_SDIFF   = "0.1234"    // The startvalue for the random-generator for SANGLEDIFF (FLOAT)
  147. #end
  148.  
  149. #ifndef ( RANDINIT_NRBDIFF)
  150.    #declare RANDINIT_NRBDIFF = "0.1234"    // The startvalue for the random-generator for  NRBDIFF (FLOAT)
  151. #end
  152.  
  153. #ifndef ( RANDINIT_NRLDIFF)
  154.    #declare RANDINIT_NRLDIFF = "0.1234"    // The startvalue for the random-generator for NRLDIFF (FLOAT)
  155. #end
  156.  
  157. #ifndef ( RANDINIT_LEAFSELECT)
  158.    #declare RANDINIT_LEAFSELECT = "0.1234" // The startvalue for the random-generator for the selection of leafs. (FLOAT)
  159. #end
  160.  
  161. #ifndef ( RANDINIT_LEAFTRANS)
  162.    #declare RANDINIT_LEAFTRANS = "0.1234"  // The startvalue for the random-generator for the placing of the leafs on the braches. (FLOAT)
  163. #end
  164.  
  165. #ifndef ( RANDINIT_LEAFROT)
  166.    #declare RANDINIT_LEAFROT = "0.1234"    // The startvalue for the random-generator for the rotation of the leafs. (FLOAT)
  167. #end
  168.  
  169. #ifndef ( RANDINIT_BT)
  170.    #declare RANDINIT_BT      = "0.1234"    // The startvalue for the random-generator for BRANCHTOP (FLOAT)
  171. #end
  172.  
  173. // Default-Texture, you should always have one
  174. #default { pigment { color rgb <0.35, 0.16, 0.14> } }
  175.  
  176.  
  177.  
  178. /*********************************************************************
  179. **********************************************************************
  180. **********************************************************************
  181. ***                                                                ***
  182. ***         DO NOT CHANGE ANYTHING BELOW HERE                      ***
  183. ***                                                                ***
  184. **********************************************************************
  185. **********************************************************************
  186. *********************************************************************/
  187.  
  188.  
  189.  
  190. /*********************************************************************
  191. *                                                                    *
  192. * Now produce the tree-include and write it to the debug-stream      *
  193. *                                                                    *
  194. *********************************************************************/
  195.  
  196.  
  197. #debug        "/*********************************************************************\n"
  198. #debug        "\n"
  199. #debug concat("   Objectname: ",OBJECTNAME,"\n")
  200. #debug        "\n"
  201. #debug        "*********************************************************************/\n\n"
  202.  
  203. // Initializing the random-streams
  204. #debug concat("#declare RANDROT_",OBJECTNAME,"        = seed(",RANDINIT_ROT,") // random for rotation\n")
  205. #debug concat("#declare RANDLDIFF_",OBJECTNAME,"      = seed(",RANDINIT_LDIFF,") // random for LDIFF\n")
  206. #debug concat("#declare RANDRDIFF_",OBJECTNAME,"      = seed(",RANDINIT_RDIFF,") // random for RDIFF\n")
  207. #debug concat("#declare RANDSDIFF_",OBJECTNAME,"      = seed(",RANDINIT_SDIFF,") // random for SANGLEDIFF\n")
  208. #debug concat("#declare RANDNRBDIFF_",OBJECTNAME,"    = seed(",RANDINIT_NRBDIFF,") // random for NRBDIFF\n")
  209. #debug concat("#declare RANDNRLDIFF_",OBJECTNAME,"    = seed(",RANDINIT_NRLDIFF,") // random for NRLDIFF\n")
  210. #debug concat("#declare RANDLEAFROT_",OBJECTNAME,"    = seed(",RANDINIT_LEAFROT,") // random for LEAFROT\n")
  211. #debug concat("#declare RANDLEAFTRANS_",OBJECTNAME,"  = seed(",RANDINIT_LEAFTRANS,") // random for LEAFTRANS\n")
  212. #debug concat("#declare RANDLEAFSELECT_",OBJECTNAME," = seed(",RANDINIT_LEAFSELECT,") // random for LEAFSELECT\n")
  213. #debug concat("#declare RANDBT_",OBJECTNAME,"         = seed(",RANDINIT_BT,") // random for BRANCHTOP\n\n")
  214.  
  215.  
  216.  
  217. // Set up some Vars for Statistics
  218. // How many cones
  219. #debug "#declare NROFCONES = 0\n"
  220. // How many spheres
  221. #debug "#declare NROFSPHERES = 0\n"
  222. // How many leafs
  223. #debug "#declare NROFLEAFS = 0\n\n"
  224.  
  225.  
  226.  
  227. // Open the union OBJECTNAME
  228. #declare INCDEPTH = 0
  229. #debug concat("#declare X = ",str(INCDEPTH,0,0),"\n")
  230. #debug        "\n"
  231. #debug concat("#declare ",OBJECTNAME," =\n")
  232. #debug        "union\n"
  233. #debug        "{\n"
  234. #debug        "   // Generate the trunk\n"
  235.  
  236. #if ( strcmp(USESTDTRUNK,"NO") != 0 )
  237.    #debug        "   union\n"
  238.    #debug        "   {\n"
  239.    #debug concat("       cone { <0, 0, 0>, ",TRUNKBASER,", <0, ",TRUNKLEN,", 0>, ",TRUNKCAPR," }\n")
  240.    #debug        "       #declare NROFCONES = NROFCONES + 1\n"
  241.    #debug concat("       sphere { <0, ",TRUNKLEN,", 0>, ",TRUNKCAPR," }\n")
  242.    #debug        "       #declare NROFSPHERES = NROFSPHERES + 1\n"
  243.    #debug concat("       #ifdef ( MOD_TR )\n")
  244.    #debug        "          // if defined, insert the texture-modifier\n"
  245.    #debug concat("          texture { MOD_TR }\n")
  246.    #debug        "       #end\n"
  247.    #debug        "   }\n"
  248. #else
  249.    #debug        "   object\n"
  250.    #debug        "   {\n"
  251.    #debug        "      NEWTRUNK\n"
  252.    #debug        "   }\n"
  253. #end
  254.  
  255. // Generate th erest of the tree
  256. // First while-statement: Open all recursion-levels
  257.  
  258. #while ( INCDEPTH < DEPTH )
  259.    #debug           "// Set loop-counter to number of number of branches + difference\n"
  260.    #debug           "// in dependance to the actual recursion-step.\n"
  261.    #debug    concat("#declare X = ",str(INCDEPTH,0,0),"\n")
  262.    #debug    concat("#declare DEPTH_",str(INCDEPTH,0,0)," = (",NRBRANCHES,"+(rand(RANDNRBDIFF_",OBJECTNAME,")*",NRBDIFF,"))*pow(",NRBSCALEMUL,",",str(INCDEPTH,0,0),")+(",NRBSCALEADD,"*",str(INCDEPTH,0,0),")\n")
  263.    #debug    concat("#while ( DEPTH_",str(INCDEPTH,0,0)," > 0 )\n")
  264.    #if ( INCDEPTH != DEPTH-1 )
  265.       #debug concat("   // recursion step: ",str(INCDEPTH,0,0),"\n")
  266.       #debug        "   union\n"
  267.       #debug        "   {\n"
  268.       #debug        "      // compute the actual branch-radius\n"
  269.       #debug concat("      #declare ACTRAD = (",RADIUS,"-(rand(RANDRDIFF_",OBJECTNAME,")*",RDIFF,"))*pow(",RADSCALE,",",str(INCDEPTH,0,0),") \n")
  270.       #debug        "      // compute actual branch-length\n"
  271.       #debug concat("      #declare BLEN_",str(INCDEPTH,0,0)," = (",BLEN,"+(rand(RANDLDIFF_",OBJECTNAME,")*",LDIFF,"))*pow(",RECSCALE,",",str(INCDEPTH,0,0),")\n")
  272.       #debug concat("      cone { <0, 0, 0>, ACTRAD, <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*(",RADSCALE,") }\n")
  273.       #debug        "      #declare NROFCONES = NROFCONES + 1\n"
  274.       #debug concat("      sphere { <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*(",RADSCALE,") }\n")
  275.       #debug        "      #declare NROFSPHERES = NROFSPHERES + 1\n"
  276.  
  277.    #else
  278.       #if ( strcmp(LEAFINC,"YES") = 0 )
  279.          #debug     "   union\n"
  280.       #else
  281.          #debug     "   object\n"
  282.       #end
  283.       #debug        "   {\n"
  284.       #debug        "      // compute the actual branch-radius\n"
  285.       #debug concat("      #declare ACTRAD = (",RADIUS,"-(rand(RANDRDIFF_",OBJECTNAME,"))*",RDIFF,")*pow(",RADSCALE,",",str(INCDEPTH,0,0),") \n")
  286.       #debug        "      // lowest branch-level without closing sphere\n"
  287.       #debug concat("      #declare BLEN_",str(INCDEPTH,0,0)," = (",BLEN,"+(rand(RANDLDIFF_",OBJECTNAME,")*",LDIFF,"))*pow(",RECSCALE,",",str(INCDEPTH,0,0),")\n")
  288.       #debug concat("      cone { <0, 0, 0>, ACTRAD, <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*",RADSCALE," }\n")
  289.       #debug        "      #declare NROFCONES = NROFCONES + 1\n"
  290.  
  291.       #if ( strcmp(LEAFINC,"YES") = 0 )
  292.          #debug        "      // generate the leafs\n"
  293.          #debug        "      // leaf-counter\n"
  294.          #debug concat("      #declare LEAFCNT = ",NRLEAFS," + (int(rand(RANDNRLDIFF_",OBJECTNAME,")*",NRLDIFF,"))\n")
  295.          #debug        "      #while ( LEAFCNT > 0 )\n"
  296.          #debug        "         object\n"
  297.          #debug        "         {\n"
  298.          #debug        "            // choose a leaf\n"
  299.          #debug concat("            #switch( int( rand(RANDLEAFSELECT_",OBJECTNAME,") * (",NRLEAFS,"-1) ) )\n")
  300.  
  301.          #declare LCOUNT = 0
  302.          #while ( LCOUNT < NRLEAFINCS )
  303.             #debug concat("               #case ( ",str(LCOUNT,0,0)," )\n")
  304.             #debug concat("                  LEAFINC_",str(LCOUNT,0,0),"\n")
  305.             #debug        "               #break\n"
  306.             #declare LCOUNT = LCOUNT + 1
  307.          #end
  308.          #debug        "               #else\n"
  309.          #debug        "                  LEAFINC_0\n"
  310.          #debug        "            #end\n"
  311.          #debug        "            #declare NROFLEAFS = NROFLEAFS + 1\n"
  312.          #debug        "            rotate <90, 0, 0>\n"
  313.          #debug concat("            #declare randy = 360*rand(RANDLEAFROT_",OBJECTNAME,")\n")
  314.          #debug concat("            rotate <0, randy, 0>\n")
  315.          #debug concat("            translate <0, rand(RANDLEAFTRANS_",OBJECTNAME,")*BLEN_",str(INCDEPTH,0,0),", 0>\n")
  316.          #debug        "         }\n"
  317.          #debug        "         #declare LEAFCNT = LEAFCNT - 1\n"
  318.          #debug        "      #end\n"
  319.       #end
  320.  
  321.    #end
  322.    #debug "\n"
  323.    #declare INCDEPTH = INCDEPTH+1
  324. #end
  325.  
  326.  
  327. // Second while-statement: include texture-modifiers, transformations and closing the recursion-levels
  328.  
  329. #declare INCDEPTH = DEPTH-1
  330. #while ( INCDEPTH != -1 )
  331.    #debug    concat("      #ifdef ( MOD_",str(INCDEPTH,0,0)," )\n")
  332.    #debug           "         // if defined, insert texture-modifier\n"
  333.    #debug    concat("         texture { MOD_",str(INCDEPTH,0,0)," }\n")
  334.    #debug           "      #end\n"
  335.    #debug           "      // branch-inclination\n"
  336.    #debug    concat("      #declare randx = (",SLOPEANGLE,"+(rand(RANDSDIFF_",OBJECTNAME,")*",SANGLEDIFF,"))*pow(",ANGLESCALE,",",str(INCDEPTH-1,0,0),")\n")
  337.    #debug    concat("      rotate <randx, 0, 0>\n")
  338.    #debug           "      // rotate within the rotation-range\n"
  339.    #debug    concat("      #declare randy = ",ROTRANGE,"*rand(RANDROT_",OBJECTNAME,")\n")
  340.    #debug    concat("      rotate <0, randy, 0>\n")
  341.    #if ( INCDEPTH > 0 )
  342.       #debug        "      // displace at the parent-branch\n"
  343.       #debug concat("      #if ( rand(RANDBT_",OBJECTNAME,") < ",BRANCHTOP," )\n")
  344.       #debug        "         // move to branch-top\n"
  345.       #debug concat("         translate <0, BLEN_",str(INCDEPTH-1,0,0),", 0>\n")
  346.       #debug        "      #else\n"
  347.       #debug        "         // move to a random point\n"
  348.       #debug concat("         translate <0, (BLEN_",str(INCDEPTH-1,0,0),")*rand(RANDBT_",OBJECTNAME,"), 0>\n")
  349.       #debug        "      #end\n"
  350.    #else
  351.       #debug        "      // move to the top of the trunk\n"
  352.       #debug concat("      translate <0, ",TRUNKLEN,", 0>\n")
  353.    #end
  354.    #debug           "   }\n"
  355.    #debug    concat("   #declare DEPTH_",str(INCDEPTH,0,0)," = DEPTH_",str(INCDEPTH,0,0)," - 1\n")
  356.    #debug           "#end\n"
  357.    #declare INCDEPTH = INCDEPTH-1
  358. #end
  359.  
  360. // close the union OBJECTNAME
  361. #debug "}\n\n"
  362.  
  363.  
  364. // print out the statistics
  365. #debug        "#statistics     \"\\n\\n    SELFTREE STATISTICS:\\n\" \n"
  366. #debug        "#statistics         \" --------------------------\\n\" \n"
  367. #debug concat("#statistics  concat(\" Objectname        : ",OBJECTNAME,"\\n\") \n")
  368. #debug        "#statistics         \" --------------------------\\n\" \n"
  369. #debug        "#statistics  concat(\" Number of cones   : \",str(NROFCONES, 6, 0),\"\\n\") \n"
  370. #debug        "#statistics  concat(\" Number of spheres : \",str(NROFSPHERES, 6, 0),\"\\n\") \n"
  371. #debug        "#statistics  concat(\" Number of leafs   : \",str(NROFLEAFS, 6, 0),\"\\n\") \n"
  372. #debug        "#statistics         \" --------------------------\\n\" \n"
  373. #debug        "#statistics  concat(\" Total             : \",str(NROFLEAFS+NROFSPHERES+NROFCONES, 6, 0),\"\\n\") \n"
  374.  
  375. #debug "\n\n\n\n\n"
  376.